package com.dly.hope.controller;

import com.dly.hope.annotation.LoginRole;
import com.dly.hope.constant.R;
import com.dly.hope.model.vo.FriendAddMessageVo;
import com.dly.hope.model.vo.FriendGroupVo;
import com.dly.hope.model.vo.FriendShowVo;
import com.dly.hope.service.TieService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@Api(tags = "用户关系相关接口")
@RequestMapping(value = "/tie")
public class TieController extends BaseController {

    @Resource
    private TieService tieService;

    @GetMapping("/getFriendAddMessage")
    @ApiOperation(value = "获取好友的添加信息")
    @LoginRole
    public ResponseEntity<R<List<FriendAddMessageVo>>> getFriendAddMessage(){
        return operate(()->this.successDate(tieService.getFriendAddMessage(getCurrentUserId())));
    }

    @PostMapping("/createFriendGroup")
    @ApiOperation(value = "创建朋友分组")
    @LoginRole
    public ResponseEntity<R<Void>> createFriendGroup(String name){
        tieService.createFriendGroup(name, getCurrentUserId());
        return operate(this::success);
    }

    @PostMapping("/updateFriendGroup")
    @ApiOperation(value = "更新朋友分组")
    @LoginRole
    public ResponseEntity<R<Void>> updateFriendGroup(String friendGroupId, String name){
        tieService.updateFriendGroup(friendGroupId, name, getCurrentUserId());
        return operate(this::success);
    }

    @PostMapping("/addFriend")
    @ApiOperation(value = "添加朋友")
    @LoginRole
    public ResponseEntity<R<Void>> addFriend(String userNumber, String friendGroupId){
        tieService.addFriend(userNumber, friendGroupId, getCurrentUserId());
        return operate(this::success);
    }

    @PostMapping("/addFriendId")
    @ApiOperation(value = "添加朋友(通过Id)")
    @LoginRole
    public ResponseEntity<R<Void>> addFriendId(String userId, String friendGroupId){
        tieService.addFriendId(userId, friendGroupId, getCurrentUserId());
        return operate(this::success);
    }

    @PostMapping("/refusal")
    @ApiOperation(value = "拒绝添加")
    @LoginRole
    public ResponseEntity<R<Void>> refusalFriend(String id){
        tieService.refusalFriend(id, getCurrentUserId());
        return operate(this::success);
    }

    @PostMapping("/agree")
    @ApiOperation(value = "同意添加")
    @LoginRole
    public ResponseEntity<R<Void>> agreeFriend(String id, String friendGroupId) {
        tieService.agreeFriend(id, getCurrentUserId(), friendGroupId);
        return operate(this::success);
    }

    @GetMapping("/getFriendGroup")
    @ApiOperation(value = "获取用户的群租信息")
    @LoginRole
    public ResponseEntity<R<List<FriendGroupVo>>> getFriendGroupVo(){
        return operate(()->this.successDate(tieService.getFriendGroupVo(getCurrentUserId())));
    }

    @GetMapping("/getFriendShowVo")
    @ApiOperation(value = "获取用户的分组情况和好友信息")
    @LoginRole
    public ResponseEntity<R<List<FriendShowVo>>> getFriendShowVo(){
        return operate(()-> this.successDate(tieService.getFriendShowVo(getCurrentUserId())));
    }


    @PostMapping ("/removeFriend")
    @ApiOperation(value = "删除好友关系")
    @LoginRole
    public ResponseEntity<R<Void>> removeFriend(String friendId){
        tieService.removeFriend(getCurrentUserId(), friendId);
        return operate(this::success);
    }

    @PostMapping("/removeFriendGroup")
    @ApiOperation(value = "删除好友分组")
    @LoginRole
    public ResponseEntity<R<Void>> removeFriendGroup(String friendGroupId){
        tieService.removeFriendGroup(getCurrentUserId(), friendGroupId);
        return operate(this::success);
    }

    @PostMapping("/moveFriendGroup")
    @ApiOperation(value = "好友分组移动")
    @LoginRole
    public ResponseEntity<R<Void>> moveFriendGroup(String friendId, String friendGroupId){
        tieService.moveFriendGroup(getCurrentUserId(), friendId, friendGroupId);
        return operate(this::success);
    }

}
